package com.punai.dataanalysis.epdatakb.vo;

import cn.hutool.core.util.StrUtil;
import com.punai.common.utils.DateUtil;
import com.punai.common.utils.DateUtils;

import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class DataAnalysisVo {

    /**
     * monthrange
     * month
     * quarter
     * year
     */
    private String timeType;

    private String startTime;

    private String endTime;

    private String enumType;

    private String tabType;

    private String proName;

    private String gsName;

    private Boolean oneMonth = false;

    private String fgs;


    public String getTimeType() {
        return timeType;
    }

    public void setTimeType(String timeType) {
        this.timeType = timeType;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getEnumType() {
        return enumType;
    }

    public void setEnumType(String enumType) {
        this.enumType = enumType;
    }

    public String getTabType() {
        return tabType;
    }

    public void setTabType(String tabType) {
        this.tabType = tabType;
    }

    public String getProName() {
        return proName;
    }

    public void setProName(String proName) {
        this.proName = proName;
    }

    public String getGsName() {
        return gsName;
    }

    public void setGsName(String gsName) {
        this.gsName = gsName;
    }

    public Boolean getOneMonth() {
        return oneMonth;
    }

    public void setOneMonth(Boolean oneMonth) {
        this.oneMonth = oneMonth;
    }

    public Map<String,Object> getYearMonth() {
        Map<String, Object> yearMonth = new HashMap<>();
        String timeType = getTimeType();
        String startTime = getStartTime();
        String endTime = getEndTime();
        yearMonth.put("timeType", timeType);
        if (StrUtil.equals("monthrange", timeType)) {
            if (StrUtil.isAllNotBlank(startTime, endTime)) {
                Date sdate = DateUtils.parseDate(startTime);
                Date edate = DateUtils.parseDate(endTime);
                String year1 = DateUtil.getYear(sdate);
                String year2 = DateUtil.getYear(edate);
                String month1 = DateUtil.getMonth(sdate);
                String month2 = DateUtil.getMonth(edate);
                yearMonth.put("year1", year1);
                yearMonth.put("year2", year2);
                yearMonth.put("month1", month1);
                yearMonth.put("month2", month2);
            }
        } else if (StrUtil.equals("month", timeType)) {
            if (StrUtil.isNotBlank(startTime)) {
                Date sdate = DateUtils.parseDate(startTime);
                String year = DateUtil.getYear(sdate);
                String month = DateUtil.getMonth(sdate);
                yearMonth.put("year", year);
                yearMonth.put("month", month);
            }
        } else if (StrUtil.equals("quarter", timeType)) {
            if (StrUtil.isAllNotBlank(startTime, endTime)) {
                Date sdate = DateUtils.parseDate(startTime);
                Date edate = DateUtils.parseDate(endTime);
                String year = DateUtil.getYear(sdate);
                String month1 = DateUtil.getMonth(sdate);
                String month2 = DateUtil.getMonth(edate);
                yearMonth.put("year", year);
                yearMonth.put("month1", month1);
                yearMonth.put("month2", month2);
            }
        } else if (StrUtil.equals("year", timeType)) {
            if (StrUtil.isNotBlank(startTime)) {
                Date sdate = DateUtils.parseDate(startTime);
                String year = DateUtil.getYear(sdate);
                yearMonth.put("year", year);
            }
        }
        return yearMonth;
    }

    /**
     * 是否为第一个月
     * @return
     */
    public Boolean isMonth1() {
        // 是否为第一个月
        String month = DateUtil.getMonth(new Date());
        return StrUtil.equals(month,"01");
    }

    public String getFgs() {
        return fgs;
    }

    public void setFgs(String fgs) {
        this.fgs = fgs;
    }

    @Override
    public String toString() {
        return "DataAnalysisVo{" +
                "timeType='" + timeType + '\'' +
                ", startTime='" + startTime + '\'' +
                ", endTime='" + endTime + '\'' +
                ", enumType='" + enumType + '\'' +
                ", tabType='" + tabType + '\'' +
                ", proName='" + proName + '\'' +
                ", gsName='" + gsName + '\'' +
                ", oneMonth=" + oneMonth +
                '}';
    }
}
